package com.icow.wms.basic.utils;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.util.Date;
import java.util.Map;
import java.util.Set;

public class JsonAssignment {

    public static String getJson(String json, String taskName, Integer vehicleNo, String vehicleName, String startLocation, String endLocation) {
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            Map<String, Object> map = objectMapper.readValue(json, Map.class);
            Set<String> keys = map.keySet();
            for (String key : keys) {
                if ("任务名".equals(map.get(key))) {
                    map.put(key, taskName);
                } else if ("车辆编号".equals(map.get(key))) {
                    map.put(key, vehicleNo);
                } else if ("车辆名称".equals(map.get(key))) {
                    map.put(key, vehicleName);
                } else if ("开始站点".equals(map.get(key))) {
                    map.put(key, startLocation);
                } else if ("结束站点".equals(map.get(key))) {
                    map.put(key, endLocation);
                } else if ("最新日期".equals(map.get(key))) {
                    map.put(key, new Date());
                }
            }
            String jsonNew = objectMapper.writeValueAsString(map);
            return jsonNew;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
